/**
 * 文件流
*/

const reader = new FileReader()
reader.onload = function (event) {
    const base64 = event.target.result
    const base64ToBlob = (code) => {
        const parts = code.split(";base64,");
        const contentType = parts[0].split(":")[1];
        const raw = window.atob(parts[1]);
        const rawLength = raw.length;
        const uInt8Array = new Uint8Array(rawLength);
        for (let i = 0; i < rawLength; i++) {
            uInt8Array[i] = raw.charCodeAt(i);
        }
        return new Blob([uInt8Array], { type: contentType });
    }
    const blob = base64ToBlob(base64);
    const url = URL.createObjectURL(blob);
    console.log(url, 'url')
    that.$nextTick(() => {
        that.pdfUrl = `pdf/web/viewer.html?file=${url}`;
    })
}
reader.readAsDataURL(file)


/**
 * base64（文件特别特别大的时候不建议用）
*/

function base64ToBlob(code) {
    const parts = code.split(";base64,");
    const contentType = parts[0].split(":")[1];
    const raw = window.atob(parts[1]);
    const rawLength = raw.length;
    const uInt8Array = new Uint8Array(rawLength);
    for (let i = 0; i < rawLength; i++) {
        uInt8Array[i] = raw.charCodeAt(i);
    }
    return new Blob([uInt8Array], { type: contentType });
}
const base64 = `data:application/pdf;base64,${this.base64}`;
const blob = base64ToBlob(base64);
const url = URL.createObjectURL(blob);
this.pdfUrl = `pdf/web/viewer.html?file=${url}`;


/**
 * 按需分片加载
 * 参考地址：https://blog.csdn.net/qq_29864051/article/details/130742657?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522172317015416800213079879%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=172317015416800213079879&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-3-130742657-null-null.nonecase&utm_term=pdf&spm=1018.2226.3001.4450
*/